<?php

/**
 * 频道类目管理 -- 上架和推荐功能提交程序
 * 
 * @copyright dongping
 * @since 2012-03-20
 */




include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	// id
	cgi::both($g_cgival["id"], "id", 1);
	$g_cgival["id"] = intval($g_cgival["id"]);

	
	// op
	cgi::both($g_cgival["op"], "op", "shangjia");
	if ($g_cgival["op"] !== "shangjia" and $g_cgival["op"] != "tj")
	{
		$g_cgival["op"] = "shangjia";
	}
	
	cgi::both($g_cgival["op_value"], "op_value", 1);
	if ($g_cgival["op_value"] != 1)
	{
		$g_cgival["op_value"] = 0;
	}

}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$id = $g_cgival["id"];	
	$op = $g_cgival["op"];
	$op_value = $g_cgival["op_value"];

	if ($id <= 0)
	{
		throw new Exception("提交的参数有错误！");
	}

	
	
	// 拿到当前站点的site_id
	$site_id = admin::admin_get_user_site_id();
	$admin_id = admin::admin_get_login_uid();
	$admin_name = admin::admin_get_login_user_name();
	
	$admin_log = new admin_log();
	$db = new db_food_tag();
//  	$db->debug = true;
	

	// 判断
	if ($op == "shangjia")
	{
		$ret = $db->admin_update_tag_shangjia_by_id($id, $site_id, $op_value, $admin_id, $admin_name);
		if ($op_value == 0)
		{
			$admin_log->admin_insert_log_info($admin_id, $site_id, 7, "下架 频道类目id={$id}");
		}
		else
		{
			$admin_log->admin_insert_log_info($admin_id, $site_id, 7, "上架 频道类目id={$id}");
		}
	}
	else
	{
		$ret = $db->admin_update_tag_tj_by_id($id, $site_id,$op_value, $admin_id, $admin_name);
		if ($op_value == 0)
		{
			$admin_log->admin_insert_log_info($admin_id, $site_id, 7, "取消推荐 频道类目id={$id}");
		}
		else
		{
			$admin_log->admin_insert_log_info($admin_id, $site_id, 7, "推荐 频道类目id={$id}");
		}
	}
	
	$g_show["ret"] = $ret;
	
}

try
{

	admin_check_login();
// 	admin_check_user_priv("foodv2/main_nav.php");
	
	check_cgi_pro();
	get_data();
	
	$g_show["error"] = 0;
	$g_show["errmsg"] = "成功";	

}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_show;
	
	echo json_encode($g_show);
}

?>